<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    .box {
      position: absolute;
      top: 100px;
      left: 100px;
      width: 100px;
      height: 100px;
      background-color: skyblue;
    }
  </style>
</head>
<body>
  <input type="button" value="开始" id="start">
  <div class="box" id="box"></div>
  <script>
    var start = document.getElementById("start");
    var box = document.getElementById("box");
    var nowleft = 100;
    var nowwidth = 100;

    var endleft = 500;
    var endwidth = 300;

    var time = 2000;
    var interval = 50;
    var maxcount = (time / interval);
    var stepleft = (endleft-nowleft)/ maxcount;
    var stepwidth = (endwidth-nowwidth)/ maxcount;

    var timer;
    var count = 0;
    start.onclick = function(){
        clearInterval(timer);
        timer = setInterval(function(){
            nowleft += stepleft;
            nowwidth += stepwidth;
            
            count++; 
            if(count>=maxcount){
                nowleft = endleft;
                nowwidth = endwidth;
                clearInterval(timer);
            }
            box.style.left = nowleft + "px";
            box.style.width = nowwidth + "px";
            
        },interval);  
    }
    

  </script>
</body>
</html>